#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：henan_sumo
@File ：config40.py
@IDE ：PyCharm
@Author ：xinyingjie
@Date ：2025/5/13 8:52
'''

from utils.tools import calculate_distance

USE_LIBSUMO = False
USE_GUI = True
SHOW_SIMU = True
KAFKA_HOST = '10.100.12.58:9093'
# LIDAR_RANGE = 40
# PINJIE_DIS = 55

LIDAR_RANGE = 90
PINJIE_DIS = 50
KAFKA_E1_TOPIC = "e1_fusion_data_v3"
KAFKA_E1_OUT_1 = "e1_data_CJ-10-0"
KAFKA_E1_OUT_2 = "e1_data_CJ-10-0"
KAFKA_E1_IN_1 = "e1_data_JJ-10-0"
KAFKA_E1_IN_2 = "e1_data_JJ-10-0"
KAFKA_E1_LIST_1 = ['e1_data_CJ-10-01-0', 'e1_data_CJ-10-02-0', 'e1_data_JJ-10-01-0', 'e1_data_JJ-10-02-0']

KAFKA_E1_LIST = "fusion_E1_data"
KAFKA_E1_TOPIC_SIMU = "sumo_simu"

RADAR_DATA_LIST = {
    11: {'sn': 11, 'lon': 116.4236011, 'lat': 39.77833934, 'Downstream': {'sn': 12}, 'Upstream': None,
         'disDown': 677, 'normal': True, 'type': "jg"},
    12: {'sn': 12, 'lon': 116.4233678, 'lat': 39.77179096, 'Downstream': {'sn': 15}, 'Upstream': {'sn': 11},
         'disDown': 1018, 'normal': True, "div": "-15", 'type': "jg"},
    15: {'sn': 15, 'lon': 116.4261857, 'lat': 39.75540889, 'Downstream': {'sn': 16}, 'Upstream': {'sn': 12},
         'disDown': 1018, 'normal': True, 'type': "jg"},
    16: {'sn': 16, 'lon': 116.4285662, 'lat': 39.7464115, 'Downstream': {'sn': 18}, 'Upstream': {'sn': 15},
         'disDown': 1018, 'normal': True, "div": "-32", 'type': "jg"},
    18: {'sn': 18, 'lon': 116.4306522, 'lat': 39.73931893, 'Downstream': None, 'Upstream': {'sn': 16},
         'disDown': 1018, 'normal': True, 'type': "jg"},
    19: {'sn': 19, 'lon': 116.4310726, 'lat': 39.73943829, 'Downstream': {'sn': 21}, 'Upstream': None,
         'disDown': 2393, 'normal': True, 'type': "jg"},
    21: {'sn': 21, 'lon': 116.4280638, 'lat': 39.75005531, 'Downstream': {'sn': 22}, 'Upstream': {'sn': 19},
         'disDown': 1145, 'normal': True, 'type': "jg"},
    22: {'sn': 22, 'lon': 116.4256975, 'lat': 39.75950848, 'Downstream': {'sn': 25}, 'Upstream': {'sn': 21},
         'disDown': 363, 'normal': True, "div": "-27", 'type': "jg"},
    25: {'sn': 25, 'lon': 116.4239826, 'lat': 39.77116232, 'Downstream': {'sn': 26}, 'Upstream': {'sn': 22},
         'disDown': 777, 'normal': True, 'type': "jg"},
    26: {'sn': 26, 'lon': 116.4240484, 'lat': 39.77798255, 'Downstream': None, 'Upstream': {'sn': 25},
         'disDown': 578, 'normal': True, 'type': "jg"},
    13: {'sn': 13, 'lon': 116.42371, 'lat': 39.76847134, 'Downstream': None, 'Upstream': None,
         'disDown': 677, 'normal': True, 'arrive': '-56', 'type': "hm"},
    14: {'sn': 14, 'lon': 116.4247321, 'lat': 39.76152304, 'Downstream': {'sn': 15}, 'Upstream': None,
         'disDown': 1018, 'normal': True, 'type': "hm"},
    17: {'sn': 17, 'lon': 116.4290889, 'lat': 39.74394431, 'Downstream': None, 'Upstream': None,
         'disDown': 1018, 'normal': True, 'arrive': '-65', 'type': "hm"},
    20: {'sn': 20, 'lon': 116.4299701, 'lat': 39.7434342, 'Downstream': {'sn': 21}, 'Upstream': None,
         'disDown': 1018, 'normal': True, 'type': "hm"},
    23: {'sn': 23, 'lon': 116.4254769, 'lat': 39.7616087, 'Downstream': None, 'Upstream': {'sn': 16},
         'disDown': 1018, 'normal': True, 'arrive': '-0', 'type': "hm"},
    24: {'sn': 24, 'lon': 116.4244934, 'lat': 39.7685285, 'Downstream': {'sn': 25}, 'Upstream': None,
         'disDown': 2393, 'normal': True, 'type': "hm"},
}

RADAR_DATA_LIST_JJ = {
    9: {'sn': 9, 'lon': 116.4310726, 'lat': 39.73943829, 'Downstream': {'sn': 11}, 'Upstream': None, 'type': "jg",
        'topic': "e1_data_JJ-10-01", 'orgCode': "JJ-10-01", 'normal': True},
    10: {'sn': 10, 'lon': 116.4299701, 'Downstream': {'sn': 11}, 'Upstream': None, 'type': "hm",
         'topic': "e1_data_JJ-10-02", 'orgCode': "JJ-10-02", 'normal': True},
    11: {'sn': 11, 'lon': 116.4280638, 'Downstream': {'sn': 12}, 'Upstream': {'sn': 9}, 'HMUpstream': {'sn': 10},
         'type': "jg", 'topic': "e1_data_JJ-10-03", 'orgCode': "JJ-10-03", 'normal': True},
    12: {'sn': 12, 'lon': 116.4256975, 'Downstream': {'sn': 15}, 'HMDownstream': {'sn': 13}, 'Upstream': {'sn': 11},
         'type': "jg", 'topic': "e1_data_JJ-10-04", 'orgCode': "JJ-10-04", 'normal': True},
    13: {'sn': 13, 'lon': 116.4254769, 'lat': 39.7616087, 'Downstream': None, 'Upstream': {'sn': 12}, 'type': "hm",
         'arrive': '-0', 'topic': "e1_data_JJ-10-05", 'orgCode': "JJ-10-05", 'normal': True},
    14: {'sn': 14, 'lon': 116.4244934, 'lat': 39.7685285, 'Downstream': {'sn': 15}, 'Upstream': None, 'type': "hm",
         'topic': "e1_data_JJ-10-06", 'orgCode': "JJ-10-06", 'normal': True},
    15: {'sn': 15, 'lon': 116.4239826, 'Downstream': {'sn': 16}, 'Upstream': {'sn': 12}, 'HMUpstream': {'sn': 14},
         'type': "jg", 'topic': "e1_data_JJ-10-07", 'orgCode': "JJ-10-07", 'normal': True},
    16: {'sn': 16, 'lon': 116.4240484, 'lat': 39.77798255, 'Downstream': None, 'Upstream': {'sn': 15}, 'type': "jg",
         'topic': "e1_data_JJ-10-08", 'orgCode': "JJ-10-08", 'normal': True},

}

HAO_MI_RADAR_DATA_LIST = {
    13: {'sn': 13, 'lon': 116.42371, 'lat': 39.76847134, 'Downstream': None, 'Upstream': None,
         'disDown': 677, 'normal': True, 'arrive': '-56', 'type': "hm"},
    14: {'sn': 14, 'lon': 116.4247321, 'lat': 39.76152304, 'Downstream': {'sn': 15}, 'Upstream': None,
         'disDown': 1018, 'normal': True, 'type': "hm"},
    17: {'sn': 17, 'lon': 116.4290889, 'lat': 39.74394431, 'Downstream': None, 'Upstream': None,
         'disDown': 1018, 'normal': True, 'arrive': '-65', 'type': "hm"},
    20: {'sn': 20, 'lon': 116.4299701, 'lat': 39.7434342, 'Downstream': {'sn': 21}, 'Upstream': None,
         'disDown': 1018, 'normal': True, 'type': "hm"},
    23: {'sn': 23, 'lon': 116.4254769, 'lat': 39.7616087, 'Downstream': None, 'Upstream': {'sn': 16},
         'disDown': 1018, 'normal': True, 'arrive': '-0', 'type': "hm"},
    24: {'sn': 24, 'lon': 116.4244934, 'lat': 39.7685285, 'Downstream': {'sn': 25}, 'Upstream': None,
         'disDown': 2393, 'normal': True, 'type': "hm"},

}

# 全局中心点
GLOBAL_POLYGON_CENTER = [(4448.62, 202.30), (4408.84, 896.84),
                         (3674.53, 890.73), (3738.78, -76.12)]

MAX_SPEED = int(150 / 3.6)
MIN_SPEED = int(30 / 3.6)
CAR_DEFAULT_SPEED = 24
TRUCK_DEFAULT_SPEED = 20
SPECIAL_DEFAULT_SPEED = 18
# 经度逐渐减少
# 感知 第一种出现位置直接发车
# 第二个门架位置进行删车操作

erId_dict = {
    "S001933030055210010": {"lon": 121.159129, "lat": 28.23522},
    "S001933030055210011": {"lon": 121.154497, "lat": 28.238024},  # 删除  all-data没有上报这条数据，就删除
    "S001933030055210012": {"lon": 121.15025, "lat": 28.239659},
    "S001933030055210013": {"lon": 121.144683, "lat": 28.241137},
    "S001933030055210014": {"lon": 121.139778, "lat": 28.24239},
    "S001933030055210015": {"lon": 121.135468, "lat": 28.243534},
    "S001933030055210016": {"lon": 121.128253, "lat": 28.244775},
    "S001933030055210017": {"lon": 121.124437, "lat": 28.244834}}

type_change = {1: 1, 2: 12, 3: 3}
# route_list = ['-6', '-3', '-14', '-0', '-7', '-2', '-11', '-13', '-10', '-5', '-9', '-8', '-1']
route_list = {
    "0": [
        ['80', '74', '9', '85', '84', '-51', '-16', '-10', '-91', '-92', '-105', '-106'],
        ['80', '74', '9', '85', '88', '-44', '-6', '-65', '-92', '-105', '-106'],
        ['80', '74', '9', '13', '12', '-60', '-34', '-41', '-14', '-106'],
        ['80', '74', '9', '13', '-26', '-45', '-41', '-14', '-106'],
    ],
    "1": [
        ['25', '55', '109', '37', '36', '-108', '-27', '-11', '-53', '-66', '-99', '-83'],
        ['25', '55', '109', '37', '-102', '-75', '-11', '-53', '-66', '-99', '-83'],
        ['25', '55', '109', '81', '72', '71', '-21', '-33', '-2', '-3', '-66', '-99', '-83'],
        ['25', '55', '109', '81', '72', '24', '-93', '-94', '-3', '-66', '-99', '-83'],
    ],
    "2": [
        ['18', '17', '70', '69', '-39', '-57', '-63', '-64', '-96', '-97', '-48', '-47'],
        ['18', '17', '70', '59', '-38', '-101', '-76', '-64', '-96', '-97', '-48', '-47'],
        ['18', '79', '104', '-90', '-46', '-42', '-43', '-97', '-48', '-47'],
        ['18', '79', '104', '68', '73', '-28', '-61', '-0', '-43', '-97', '-48', '-47'],
        ['18', '29', '77', '-22', '-103', '-19', '-30', '-31', '-58', '-97', '-48', '-47'],
        ['18', '29', '77', '-89', '-35', '-40', '-32', '-31', '-58', '-97', '-48', '-47'],
        ['18', '29', '77', '-100', '-82', '-54', '-78', '-31', '-58', '-97', '-48', '-47'],
    ],
}

if __name__ == '__main__':
    # print(list(RADAR_DATA_LIST.keys()))
    # for sn in list(RADAR_DATA_LIST.keys()):
    #     one = RADAR_DATA_LIST[sn]
    #     if one['Downstream']:
    #         print(one['lon'], one['lat'], RADAR_DATA_LIST[one['Downstream']['sn']]['lon'],
    #               RADAR_DATA_LIST[one['Downstream']['sn']]['lat'])
    #         print(calculate_distance(one['lon'], one['lat'], RADAR_DATA_LIST[one['Downstream']['sn']]['lon'],
    #                                  RADAR_DATA_LIST[one['Downstream']['sn']]['lat']))
    result = {}
    for RADAR_DATA in RADAR_DATA_LIST:
        # down_sn = {RADAR_DATA['sn'].split("_")[0] + str(int(RADAR_DATA['sn'].split("_")[1]) + 1)}
        RADAR_DATA['Downstream'] = {
            'sn': RADAR_DATA['sn'].split("_")[0] + "_" + str(int(RADAR_DATA['sn'].split("_")[1]) + 1)}
        RADAR_DATA['Upstream'] = {
            'sn': RADAR_DATA['sn'].split("_")[0] + "_" + str(int(RADAR_DATA['sn'].split("_")[1]) - 1)}
        RADAR_DATA['disDown'] = 1000
        RADAR_DATA['normal'] = True
        result[RADAR_DATA['sn']] = RADAR_DATA

    for k, v in result.items():
        if v['Downstream']['sn'] not in result.keys():
            result[k]['Downstream'] = None
        if v['Upstream']['sn'] not in result.keys():
            result[k]['Upstream'] = None
    print(result)
